//
//  WMMusicVCBase.m
//  WholeMusic
//
//  Created by quanxiong on 2018/2/24.
//  Copyright © 2018年 quanxiong. All rights reserved.
//

#import "WMMusicVCBase.h"

@interface WMMusicVCBase ()

@end

@implementation WMMusicVCBase

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    _tableView.tableFooterView = [UIView new];
    _tableView.estimatedRowHeight = 60;
    _tableView.rowHeight = UITableViewAutomaticDimension;
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleInterreption:) name:AVAudioSessionInterruptionNotification object:[AVAudioSession sharedInstance]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - tableView delegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 60;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    //子类实现
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //子类实现
    return nil;
}

#pragma mark - 补齐分割线
- (void)viewDidLayoutSubviews {
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        self.tableView.separatorInset = UIEdgeInsetsZero;
    }
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        self.tableView.layoutMargins = UIEdgeInsetsZero;
    }
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    UIEdgeInsets edgeInsets = UIEdgeInsetsZero;
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        cell.separatorInset = edgeInsets;
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        cell.layoutMargins = edgeInsets;
    }
}
//-->实现接收到中断通知时的方法
//处理中断事件

-(void)handleInterreption:(NSNotification *)sender
{
    if(_played)
    {
        [self.player pause];
        _played = NO;
    }
    else
    {
        [self.player play];
        _played = YES;
    }
}
@end
